#pragma once
#include <iostream>
#include <string>
using namespace std;

// class Task
// {
// public:
//     Task(int x, int y):_x(x),_y(y)
//     {}
//     ~Task()
//     {}
//     void run()
//     {
//         printf("%d+%d=%d\n", _x, _y, _x+_y);
//     }
// private:
//     int _x;
//     int _y;
// };

string oper = "+-*/%";
enum
{
    DivZero = 1,
    MonZero = 2,
    Unknown = 3
};
class Task
{
public:
    Task()
    {}
    Task(int data1, int data2, char oper) : _data1(data1), _data2(data2), _oper(oper)
    {
    }
    ~Task()
    {
    }

    void run()
    {
        switch (_oper)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
        {
            if (_data2 == 0)
                _exitcode = DivZero;
            else
                _result = _data1 / _data2;
            break;
        }
        case '%':
        {
            if (_data2 == 0)
                _exitcode = MonZero;
            else
                _result = _data1 % _data2;
            break;
        }
        default:
        {
            _exitcode = Unknown;
            break;
        }
        }
    }

    string GetTask()
    {
        string s;
        s += to_string(_data1);
        s += _oper;
        s += to_string(_data2);
        s += "=?";
        return s;
    }
    string GetResult()
    {
        string s;
        s += to_string(_data1);
        s += _oper;
        s += to_string(_data2);
        s += "=";
        s += to_string(_result);
        s += "[exit code:";
        s += to_string(_exitcode);
        s += "]";
        return s;
    }

    void operator()()
    {
        run();
    }

private:
    int _data1;
    int _data2;
    char _oper;
    int _exitcode = 0;
    int _result;
};
